package com.ant.business.system.service.impl;

import com.ant.business.system.entity.RoleModule;
import com.ant.business.system.mapper.RoleModuleDao;
import com.ant.business.system.service.RoleModuleService;
import com.ant.common.exceptions.BusinessException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 角色模块管理Service实现类
 * @author
 * @description
 * @create 2021-03-22 14:25:56
 */
@Service("roleModuleService")
@Transactional(rollbackFor = Throwable.class)
public class RoleModuleServiceImpl extends ServiceImpl<RoleModuleDao, RoleModule> implements RoleModuleService {

    private final RoleModuleDao roleModuleDao;

    public RoleModuleServiceImpl(RoleModuleDao roleModuleDao) {
        this.roleModuleDao = roleModuleDao;
    }

    /**
     * 分页查询列表
     * @param page
     * @param limit
     * @return
     */
    @Override
    public PageInfo<RoleModule> getList(int page, int limit) {
        QueryWrapper<RoleModule> wrapper = new QueryWrapper<>();
        PageHelper.startPage(page, limit);
        List<RoleModule> list = roleModuleDao.selectList(wrapper);
        return new PageInfo<RoleModule>(list);
    }

    /**
     * 新增信息
     * @param roleModule
     */
    @Override
    @SneakyThrows
    public void saveOne(RoleModule roleModule) {
        int count = roleModuleDao.insert(roleModule);
        if (count!=1){
            throw new BusinessException("保存失败");
        }
    }

    /**
     * 更新信息
     * @param roleModule
     */
    @Override
    @SneakyThrows
    public void update(RoleModule roleModule) {
        int count = roleModuleDao.updateById(roleModule);
        if (count!=1){
            throw new BusinessException("更新失败");
        }
    }

    /**
     * 删除信息
     * @param primaryKey
     */
    @Override
    @SneakyThrows
    public void delete(String primaryKey) {
        int count = roleModuleDao.deleteById(primaryKey);
        if (count!=1){
            throw new BusinessException("删除失败");
        }
    }
}
